package fragment;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;

import com.lanou.horo.myapplication.R;

import java.util.zip.Inflater;

import fragment.tabhostFragment.SearchFragment;

/**
 * Created by dllo on 15/12/5.
 */
public class AlbumPageFragmentRecom extends AbsBaseFragment implements View.OnClickListener {
    private ImageView albumpage_recom_search, albumpage_recom_back;
    private TabHost mHost;
    private FragmentManager fm;
    public String hotName = "hot";
    public String newName = "recent";
    public String classicName = "classic";

    @Override
    protected int getLayoutView() {
        return R.layout.albumpage_recom_fragment;
    }

    @Override
    protected void initView() {
        albumpage_recom_search = findView(R.id.albumpage_recom_search);
        albumpage_recom_back = findView(R.id.albumpage_recom_back);
        mHost = findView(android.R.id.tabhost);

        albumpage_recom_search.setOnClickListener(this);
        albumpage_recom_back.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        initTabHost();
    }

    private void initTabHost() {
        mHost.setup();
        LayoutInflater inflater = LayoutInflater.from(getContext());
        mHost.addTab(mHost.newTabSpec("hotSpeac").setContent(R.id.hotView)
                .setIndicator(inflater.inflate(R.layout.tab_albumpage_recom_hot, null)));
        mHost.addTab(mHost.newTabSpec("newSpeac").setContent(R.id.newView)
                .setIndicator(inflater.inflate(R.layout.tab_albumpage_recom_new, null)));
        mHost.addTab(mHost.newTabSpec("classicSpeac").setContent(R.id.classicView)
                .setIndicator(inflater.inflate(R.layout.tab_albumpage_recom_classic, null)));

        fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.classicView, new AlbumpageRecomTabFragment(classicName));
        ft.replace(R.id.hotView, new AlbumpageRecomTabFragment(hotName));
        ft.replace(R.id.newView, new AlbumpageRecomTabFragment(newName));
        ft.commit();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.albumpage_recom_back:
                goBack();
                break;
            case R.id.albumpage_recom_search:
                goToNext(new SearchFragment());
                break;
        }
    }


}
